<template>
  <div class="v-manage">
    <div class="pay-box" @click="bindCard">工资卡绑定<img src="../../assets/img/arrow.png" class="arrow" onclick="return false"/></div>
    <div class="pay-box" @click="withPwd">修改提现密码<img src="../../assets/img/arrow.png" class="arrow" onclick="return false"/></div>

    <v-dialog v-model="modalVal" content="请先进行工资卡绑定" type="default" @sure="addCard"></v-dialog>

  </div>
</template>

<script>
  import dialog from "../../components/dialog"
  import {Base64} from "js-base64"
  import {getSessionStore, removeSessionStore, setSessionStore} from "../../config/util"
  import {baseUrl} from "../../config/env"

  export default {
    data() {
      return {
        modalVal: false,
        userSign: ""
      }
    },
    created() {
      this.userSign = Base64.decode(getSessionStore("openid"));
    },
    methods: {
      bindCard() {//查询工资卡信息
        this.axios.get(baseUrl + "/userbank/select_bindbankcard?sgin=" + this.userSign).then((res) => {
          let resultObj = res.data;
          if (resultObj.code == 0) {
            if (resultObj.data != null) {
              let bankObj = resultObj.data;
              if (bankObj.bankNumber != "" && bankObj.bankNumber != null) {
                let regPhone = bankObj.phone; //系统手机号
                setSessionStore("reserved_phone", regPhone);
                setSessionStore("bank_user_name", bankObj.userName);
                setSessionStore("identity_no", bankObj.identityNo);
                setSessionStore("card_no", bankObj.bankNumber);
                setSessionStore("bank_addr", bankObj.openBankAddr);
                setSessionStore("bank_name", bankObj.bankName);
                this.$router.push("/changecard");
              } else {//驻场手动输入姓名和身份证
                setSessionStore("bank_user_name", bankObj.userName);
                setSessionStore("identity_no", bankObj.identityNo);
                this.$router.push("/identywrite_asce");
              }
            } else {
              removeSessionStore("reserved_phone");
              removeSessionStore("bank_user_name");
              removeSessionStore("identity_no");
              removeSessionStore("card_no");
              removeSessionStore("bank_addr");
              removeSessionStore("bank_name");
              this.$router.push("/bindcard");
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        });
      },
      addCard() {//跳转绑定工资卡
        this.modalVal = false;
      },
      withPwd() {//修改提现密码
        this.axios.get(baseUrl + "/userbank/select_bindbankcard?sgin=" + this.userSign).then((res) => {
          let resultObj = res.data;
          if (resultObj.code == 0) {
            if (resultObj.data != null) {
              let bankObj = resultObj.data;
              if (bankObj.bankNumber != "" && bankObj.bankNumber != null) {
                let regPhone = bankObj.phone; //系统手机号
                setSessionStore("reserved_phone", regPhone);
                sessionStorage.removeItem("changecard_sign");
                this.$router.push("/withdraw_pwd");
              } else {
                this.modalVal = true;
              }
            } else {
              this.modalVal = true;
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        });
      }
    },
    components: {
      "v-dialog": dialog
    }
  }
</script>

<style lang="stylus" scoped>
  .v-manage
    width: 100%
    height: 100%
    overflow: hidden
    .pay-box
      display: flex
      align-items: center
      padding-left: 0.6rem
      height: 1.333rem
      font-size: 0.44rem
      color: rgba(68, 68, 68, 1)
      border-bottom: 1px solid rgba(230, 230, 230, 1)
      .arrow
        margin-left: auto
        margin-right: 0.333rem
        width: 0.213rem
        height: 0.373rem
</style>
